package com.app.business.show;

import com.alibaba.fastjson.JSON;
import com.app.business.en.HouseStatus;
import com.app.business.en.Status;
import com.app.business.model.*;
import com.app.business.service.*;
import com.app.business.utils.ChooseLimitUtils;
import com.app.system.jpa.PageBean;
import com.app.system.permission.model.DataDict;
import com.app.system.permission.service.DataDictService;
import com.app.system.utils.CollectionUtils;
import com.app.system.utils.ParamUtils;
import com.app.system.utils.dataType.DateUtils;
import com.app.system.utils.dataType.IntegerUtils;
import com.app.system.utils.dataType.StringUtils;
import com.app.system.utils.exception.Precondition;
import com.app.system.utils.exception.Response;
import com.app.system.utils.page.LayUiUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.transaction.Transactional;
import java.beans.Transient;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 凤林花苑（二期）回迁安置项目大屏公示
 * Created by szy on 2024/3/1
 */
@Controller
@RequestMapping("/showForFl2024/*")
@SuppressWarnings("all")
public class ShowForFl2024Controller {
    @Autowired
    private ContractService contractService;
    @Autowired
    private ZsProjectService zsProjectService;
    @Autowired
    private AzProjectService azProjectService;
    @Autowired
    private DataDictService dataDictService;
    @Autowired
    private HouseService houseService;
    @Autowired
    private ShowHjService showHjService;
    @Autowired
    private CarLotService carLotService;
    @Autowired
    private StorageRoomService storageRoomService;
    @Autowired
    private YxHouseService yxHouseService;
    @Autowired
    private YxCarLotService yxCarLotService;
    @Autowired
    private BzYyDateService bzYyDateService;
    /*********************************2024-12-25办证手机预约***********************************/

    /**
     * 预约办证
     * @param modelMap
     */
    @RequestMapping("yzBzCode")
    public void yzBzCode(ModelMap modelMap) {
    }

    /**
     * 预选办证进入
     * @param request
     * @param modelMap
     */
    @RequestMapping("yxBzYz")
    @ResponseBody
    public String yxBzYz(HttpServletRequest request) {
        String chooseHouseNum = ParamUtils.getString(request, "chooseHouseNum", "");
        String idCardFour = ParamUtils.getString(request, "idCardFour", "");
        if (this.contractService.getJqStatus(chooseHouseNum,idCardFour).equals("2")) {//若是已结清
            return this.contractService.validateForYyBz(chooseHouseNum,idCardFour);//直接返回至预约
        } else if (this.contractService.getJqStatus(chooseHouseNum,idCardFour).equals("1") || this.contractService.getJqStatus(chooseHouseNum,idCardFour).equals("3")) {//若暂未结清 不可预约办证
            return "5050";
        } else {
            return "0000";
        }
    }

    /**
     * 办证预约主界面
     * @param request
     * @param modelMap
     */
    @RequestMapping("bzYyMain")
    public void bzYyMain(HttpServletRequest request, ModelMap modelMap) {
        // 获取加密的 contractId
        String encodedContractId = request.getParameter("DF-TF-ST");
        // 先解密 contractId（假设前端使用的是 Base64 编码）
        Integer contractId = 0;
        if (encodedContractId != null && !encodedContractId.isEmpty()) {
            try {
                // Base64 解码
                byte[] decodedBytes = Base64.getDecoder().decode(encodedContractId);
                String decodedContractId = new String(decodedBytes);
                // 转换为 Integer 类型
                contractId = Integer.parseInt(decodedContractId);
            } catch (Exception e) {
                throw new IllegalArgumentException("Invalid contractId");
            }
        }
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null && contract.getZsProject() != null, "数据错误，请重试！");
        //通过征收项目id获取所分配的安置项目id
        List<String> azProjectIdList = this.houseService.getAzProjectIdListByZsProjectId(contract.getZsProject().getId());
        Map<String, AzProject> azProjectMap = this.azProjectService.getAzProjectMap();

        List<Map> dateListStr = this.bzYyDateService.getBzYyDateStrList();
        modelMap.addAttribute("dateListStr",dateListStr);

        //时间对应预约数量
        Map<String,String> getBzYyNumMap = this.contractService.getBzYyNumMap();
        modelMap.addAttribute("getBzYyNumMap",getBzYyNumMap);

        modelMap.addAttribute("contract", contract);
        modelMap.addAttribute("azProjectIdList", azProjectIdList);
        modelMap.addAttribute("azProjectMap", azProjectMap);
    }

    /**
     * 加载已选数据
     *
     * @return
     */
    @RequestMapping("loadChooseHouseInfo")
    @ResponseBody
    public Map loadChooseHouseInfo(HttpServletRequest request) {
        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        List<Map> resultData = Lists.newLinkedList();
        Map<String, DataDict> houseTypeMap = this.dataDictService.getMapByParentNameForValue("房屋类型");
        Map<String, DataDict> houseHoldMap = this.dataDictService.getMapByParentNameForValue("房屋户型");
        Map<String, DataDict> houseStatusMap = this.dataDictService.getMapByParentNameForValue("房源状态");

        List<House> yxHouseList = this.houseService.getHouseListByConId(contractId);
        if (CollectionUtils.isNotEmpty(yxHouseList)) {
            Map<String, Object> mapItem = null;
            for (House house : yxHouseList) {
                mapItem = null;
                mapItem = Maps.newHashMap();
                mapItem.put("id", house.getId());
                mapItem.put("contractId",contractId);
                mapItem.put("projectName", house.getAzProject().getProjectName());
                String houseInfo = house.getAzProject().getMemo() + "-" + house.getHouseNumStr() + "【" + house.getBuildArea() + "m²、" + houseHoldMap.get(house.getHouseHold()).getName()+ "】";
                if (house.getHouseStatus() == 2) {
                    houseInfo = "<span style='color: green'>" +  houseInfo +"</span>";
                }

                mapItem.put("houseInfo", houseInfo);

                mapItem.put("houseHoldStr",houseHoldMap.get(house.getHouseHold()).getName());
                mapItem.put("houseStatusStr",houseStatusMap.get(house.getHouseStatus().toString()).getName());
                mapItem.put("buildArea", house.getBuildArea());
                resultData.add(mapItem);
            }
        }
        return LayUiUtils.page(0, resultData);
    }

    /**
     * 加载已选车位数据
     *
     * @return
     */
    @RequestMapping("loadChooseCarLotInfo")
    @ResponseBody
    public Map loadChooseCarLotInfo(HttpServletRequest request) {
        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        List<Map> resultData = Lists.newLinkedList();
        List<CarLot> yxCarLotList = this.carLotService.getCarLotListByContractId(contractId);
        if (CollectionUtils.isNotEmpty(yxCarLotList)) {
            Map<String, Object> mapItem = null;
            for (CarLot carLot : yxCarLotList) {
                mapItem = null;
                mapItem = Maps.newHashMap();
                mapItem.put("id", carLot.getId());
                mapItem.put("contractId",contractId);
                mapItem.put("projectName", carLot.getAzProject().getProjectName());
                String carLotInfo = carLot.getAzProject().getMemo() + "-" + carLot.getHouseNumStr() + "【" + carLot.getBuildArea() + "m²" + "】";
                if (carLot.getHouseStatus() == 2) {
                    carLotInfo = "<span style='color: green'>" +  carLotInfo +"</span>";
                }
                mapItem.put("carLotInfo", carLotInfo);
                resultData.add(mapItem);
            }
        }
        return LayUiUtils.page(0, resultData);
    }

    /**
     * 办证预选号选择
     */
    @RequestMapping("bzYxNum")
    public void bzYxNum(HttpServletRequest request, ModelMap modelMap) {

    }

    /**
     * 事务回滚及异步操作
     * 预约保存
     */
    @RequestMapping("bzYySave")
    @ResponseBody
    public synchronized String bzYySave(HttpServletRequest request) {
        String contractId = ParamUtils.getString(request, "contractId", "");
        String bzYyDate = ParamUtils.getString(request, "bzYyDate", "");
        String time = ParamUtils.getString(request, "time", "");
        int bzYyNum = this.contractService.getContractListByBzYyDateNum(bzYyDate,time);//当天预约办证总户数
        Contract contract = this.contractService.findOne(Integer.valueOf(contractId));
        if (contract.getBzYyStatus() != null && contract.getBzYyStatus() == 2) {
            return "1111";//您已经预约过，请勿重复预约！！
        } else if (bzYyNum < 15) {//最多30户
            contract.setBzYyStatus(Status.YES.getIndex());//预约办证状态  是
            contract.setBzYyDate(DateUtils.stringToDateDefault(bzYyDate));//预约办证时间
            contract.setTime(time);//预约时间段
            this.contractService.save(contract);
            return "6666";//预约成功
        } else {
            return "0000";//已超出当前预约数量
        }
    }

    /******************************手机房源预选功能*************************************************/
    /**
     * 凤林花苑(二期)主页面展示【身份验证】
     * @param modelMap
     */
    @RequestMapping("yzCode")
    public void yzCode(ModelMap modelMap) {
    }

    /**
     * 预选
     * 房源界面
     */
    @RequestMapping("yxHouse")
    public void chooseHouse(HttpServletRequest request, ModelMap modelMap) {
        // 获取加密的 contractId
        String encodedContractId = request.getParameter("DF-TF-ST");
        // 先解密 contractId（假设前端使用的是 Base64 编码）
        Integer contractId = 0;
        if (encodedContractId != null && !encodedContractId.isEmpty()) {
            try {
                // Base64 解码
                byte[] decodedBytes = Base64.getDecoder().decode(encodedContractId);
                String decodedContractId = new String(decodedBytes);
                // 转换为 Integer 类型
                contractId = Integer.parseInt(decodedContractId);
            } catch (Exception e) {
                throw new IllegalArgumentException("Invalid contractId");
            }
        }
//        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null && contract.getZsProject() != null, "数据错误，请重试！");
        //通过征收项目id获取所分配的安置项目id
        List<String> azProjectIdList = this.houseService.getAzProjectIdListByZsProjectId(contract.getZsProject().getId());
        Map<String, AzProject> azProjectMap = this.azProjectService.getAzProjectMap();
        modelMap.addAttribute("contract", contract);
        modelMap.addAttribute("azProjectIdList", azProjectIdList);
        modelMap.addAttribute("azProjectMap", azProjectMap);
    }

    /**
     * 预选
     * 楼盘图界面
     *
     * @param request
     * @param modelMap
     */
    @RequestMapping("housePicture")
    public void housePicture(HttpServletRequest request, ModelMap modelMap) {
        Integer azProjectId = ParamUtils.getInt(request, "azProjectId", 0);
        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        AzProject azProject = this.azProjectService.findOne(azProjectId);
        Precondition.checkSqdsArguement(azProject != null && contract != null, "数据错误！");
        List<String> buildNumList = this.houseService.getBuildNumListByAzProjectId(contract.getZsProject().getId(), azProject.getId(),contract.hxTypeList());
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("公示颜色");

        modelMap.addAttribute("colorMap", colorMap);
        modelMap.addAttribute("azProject", azProject);
        modelMap.addAttribute("contract", contract);
        modelMap.addAttribute("buildNumList", buildNumList);
    }

    /**
     * 加载房源基本信息
     *
     * @param request
     * @param modelMap
     */
    @RequestMapping("loadHouse")
    public void loadHouse(HttpServletRequest request, ModelMap modelMap) {
        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        Integer houseId = ParamUtils.getInt(request, "houseId", 0);
        House house = this.houseService.findOne(houseId);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(house != null && contract != null, "数据错误！");
        Map<String, DataDict> houseTypeMap = this.dataDictService.getMapByParentNameForValue("房屋类型");
        Map<String, DataDict> houseHoldMap = this.dataDictService.getMapByParentNameForValue("房屋户型");
        modelMap.addAttribute("contract", contract);
        modelMap.addAttribute("house", house);
        modelMap.addAttribute("houseTypeMap", houseTypeMap);
        modelMap.addAttribute("houseHoldMap", houseHoldMap);
    }

    //加载楼板盘
    @RequestMapping("loadHousePicture")
    @ResponseBody
    public Map loadHousePicture(HttpServletRequest request) {
        Integer zsProjectId = ParamUtils.getInt(request, "zsProjectId", 0);
        Integer azProjectId = ParamUtils.getInt(request, "azProjectId", 0);
        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        String buildNum = ParamUtils.getString(request, "buildNum", "");
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据错误！");

        //通过征收项目、安置项目、楼号得到所分配的houseList
        List<House> houseList = houseService.houseList(zsProjectId.toString(), azProjectId, buildNum,contract.hxTypeList());
        //获取某户当前不可选房源IdList
        List<Integer> houseIdList = ChooseLimitUtils.getCountChooseHouseIdListByHouseStyle(contract, azProjectId);
        //得到层号和当前楼层的List<House>对应的map
        Map<String, List<House>> floorHouseMap = houseService.getFloorHouseForHouseStatusMap(houseList, houseIdList, contract);

        Map<String, Integer> maxFloorMap = houseService.getMaxFloorMap(zsProjectId.toString(), azProjectId, buildNum);
        Integer maxFloor = maxFloorMap.get("maxFloor");
        //房源状态
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("公示颜色");
        //房屋类型
        Map<String, String> houseHoldMap = this.dataDictService.getMapByParentNameForValue_Name("房屋户型");
        Map<String, Object> map = Maps.newHashMap();
        map.put("maxFloor", maxFloor);
        map.put("floorHouseMap", floorHouseMap);
        map.put("colorMap", colorMap);
        map.put("houseHoldMap", houseHoldMap);

        String limitMemo = ChooseLimitUtils.getChooseLimitForHosuePic(contract);
        map.put("limitMemo", limitMemo);
        map.put("chooseLimitType", contract.getChooseLimitType());
        return map;
    }

    /**
     * 预选房源信息保存
     *
     * @param request
     * @return
     */
    @RequestMapping("chooseHouseYxSave")
    @ResponseBody
    public Response chooseHouseYxSave(HttpServletRequest request) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Response response = this.yxHouseService.chooseHouseYxSave(request);
        return response;
    }

    /**
     * 车位预选信息保存
     *
     * @param request
     * @return
     */
    @RequestMapping("yxCarLotSave")
    @ResponseBody
    public Response yxCarLotSave(HttpServletRequest request) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Response response = this.yxCarLotService.carLotYxSave(request);
        return response;
    }

    /**
     * 加载预选数据
     *
     * @return
     */
    @RequestMapping("loadYxHouseInfo")
    @ResponseBody
    public Map loadYxHouseInfo(HttpServletRequest request) {
        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        List<Map> resultData = Lists.newLinkedList();
        Map<String, DataDict> houseTypeMap = this.dataDictService.getMapByParentNameForValue("房屋类型");
        Map<String, DataDict> houseHoldMap = this.dataDictService.getMapByParentNameForValue("房屋户型");
        Map<String, DataDict> houseStatusMap = this.dataDictService.getMapByParentNameForValue("房源状态");

        List<House> yxHouseList = this.yxHouseService.getYxHouseList(contractId);
        if (CollectionUtils.isNotEmpty(yxHouseList)) {
            Map<String, Object> mapItem = null;
            for (House house : yxHouseList) {
                mapItem = null;
                mapItem = Maps.newHashMap();
                mapItem.put("id", house.getId());
                mapItem.put("contractId",contractId);
                mapItem.put("projectName", house.getAzProject().getProjectName());
                String houseInfo = house.getAzProject().getMemo() + "-" + house.getHouseNumStr() + "【" + house.getBuildArea() + "m²、" + houseHoldMap.get(house.getHouseHold()).getName()+"、" + houseStatusMap.get(house.getHouseStatus().toString()).getName() + "】";
                if (house.getHouseStatus() == 2) {
                    houseInfo = "<span style='color: red'>" +  houseInfo +"</span>";
                }

                mapItem.put("houseInfo", houseInfo);

                mapItem.put("houseHoldStr",houseHoldMap.get(house.getHouseHold()).getName());
                mapItem.put("houseStatusStr",houseStatusMap.get(house.getHouseStatus().toString()).getName());
                mapItem.put("buildArea", house.getBuildArea());
                resultData.add(mapItem);
            }
        }
        return LayUiUtils.page(0, resultData);
    }



    /**
     * 加载预选车位数据
     *
     * @return
     */
    @RequestMapping("loadYxCarLotInfo")
    @ResponseBody
    public Map loadYxCarLotInfo(HttpServletRequest request) {
        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        List<Map> resultData = Lists.newLinkedList();
        List<CarLot> yxCarLotList = this.yxCarLotService.getYxCarLotList(contractId);
        if (CollectionUtils.isNotEmpty(yxCarLotList)) {
            Map<String, Object> mapItem = null;
            for (CarLot carLot : yxCarLotList) {
                mapItem = null;
                mapItem = Maps.newHashMap();
                mapItem.put("id", carLot.getId());
                mapItem.put("contractId",contractId);
                mapItem.put("projectName", carLot.getAzProject().getProjectName());
                String carLotInfo = carLot.getAzProject().getMemo() + "-" + carLot.getHouseNumStr() + "【" + carLot.getBuildArea() + "m²" + "】";
                if (carLot.getHouseStatus() == 2) {
                    carLotInfo = "<span style='color: red'>" +  carLotInfo +"</span>";
                }

                mapItem.put("carLotInfo", carLotInfo);
                resultData.add(mapItem);
            }
        }
        return LayUiUtils.page(0, resultData);
    }

    /**
     * 车位撤销
     *
     * @param request
     * @return
     */
    @RequestMapping("yxHouseDelete")
    @ResponseBody
    public Response yxHouseDelete(HttpServletRequest request) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Integer houseId = ParamUtils.getInt(request, "houseId", 0);
        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        this.yxHouseService.deleteYxHouse(houseId,contractId);
        return new Response("0001", "撤销成功！");
    }

    /**
     * 车位撤销
     *
     * @param request
     * @return
     */
    @RequestMapping("yxCarLotDelete")
    @ResponseBody
    public Response yxCarLotDelete(HttpServletRequest request) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Integer carLotId = ParamUtils.getInt(request, "carLotId", 0);
        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        this.yxCarLotService.deleteYxCatLot(carLotId,contractId);
        return new Response("0001", "撤销成功！");
    }

    /**
     * 预选验证进入
     * @param request
     * @param modelMap
     */
    @RequestMapping("yxYz")
    @ResponseBody
    public String yxYz(HttpServletRequest request) {
        String chooseHouseNum = ParamUtils.getString(request, "chooseHouseNum", "");
        String idCardFour = ParamUtils.getString(request, "idCardFour", "");
        if (this.contractService.getChooseHouseStatus(chooseHouseNum,idCardFour).equals("2")) {//若是已签约
            return this.contractService.validateForYx(chooseHouseNum,idCardFour);
        } else {//若是未签约
            return this.contractService.validateForYx(chooseHouseNum,idCardFour);
        }
    }

    /**
     * 凤林花苑(二期)主页面展示
     * @param modelMap
     */
    @RequestMapping("tv")
    public void tv(ModelMap modelMap) {
    }

    /**
     * 祥鹰
     */
    @RequestMapping("houseShowXy1")
    public void houseShowXy1(HttpServletRequest request, ModelMap modelMap) {
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("公示颜色");
        modelMap.addAttribute("colorMap", colorMap);
    }

    /**
     * 凤林花苑（二期）
     * B8\B9 号楼公示
     */
    @RequestMapping("houseShowB8_B9")
    public void houseShowB8_B9(HttpServletRequest request, ModelMap modelMap) {
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("公示颜色");
        modelMap.addAttribute("colorMap", colorMap);
    }

    /**
     * 凤林花苑（二期）
     * B10\B11 号楼公示
     */
    @RequestMapping("houseShowB10_B11")
    public void houseShowB10_B11(HttpServletRequest request, ModelMap modelMap) {
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("公示颜色");
        modelMap.addAttribute("colorMap", colorMap);
    }

    /**
     * 凤林花苑一期单身公寓5号楼房源公示
     * @param request
     * @param modelMap
     */
    @RequestMapping("houseShow5")
    public void houseShow5(HttpServletRequest request, ModelMap modelMap) {
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("公示颜色");
        modelMap.addAttribute("colorMap", colorMap);
    }

    /**
     * 祥鹰
     */
    @RequestMapping("houseShowXy4")
    public void houseShowXy4(HttpServletRequest request, ModelMap modelMap) {
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("公示颜色");
        modelMap.addAttribute("colorMap", colorMap);
    }



    /**
     * 楼盘图
     *
     * @param request
     */
    @RequestMapping("housePic")
    public void housePic(HttpServletRequest request, ModelMap modelMap) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "");
        Integer azProjectId = ParamUtils.getInt(request, "azProjectId", 0);
        String buildNum = ParamUtils.getString(request, "buildNum", "");
        String floor = ParamUtils.getString(request, "floor", "");
        Integer minFloor = ParamUtils.getInt(request, "minFloor", 1);

        //通过征收项目、安置项目、楼号得到所分配的houseList
        List<House> houseList = houseService.houseList(zsProjectIdStr, azProjectId, buildNum);
        //得到层号和当前楼层的List<House>对应的map
        Map<String, Map<String, House>> floorAndHouseNumForHouseMap = houseService.getFloorAndHouseNumMap(houseList);
        //获取当前安置项目最高层
        Map<String, Integer> maxFloorMap = houseService.getMaxFloorMap(zsProjectIdStr, azProjectId, buildNum, floor);
        Integer maxFloor = maxFloorMap.get("maxFloor");
        Integer maxHouseNum = maxFloorMap.get("maxHouseNum");
        //房源状态
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("公示颜色");
        //房屋类型
        Map<String, String> houseHoldMap = this.dataDictService.getMapByParentNameForValue_Name("房屋户型");

        modelMap.addAttribute("buildNum", buildNum);
        modelMap.addAttribute("floorAndHouseNumForHouseMap", floorAndHouseNumForHouseMap);
        modelMap.addAttribute("maxFloor", maxFloor);
        modelMap.addAttribute("minFloor", minFloor);
        modelMap.addAttribute("rowNum", Math.round(maxHouseNum / 10) == 0 ? 1 : Math.round(maxHouseNum / 10));
        modelMap.addAttribute("maxHouseNum", maxHouseNum);
        modelMap.addAttribute("colorMap", colorMap);
        modelMap.addAttribute("houseHoldMap", houseHoldMap);
    }

    /**
     * 共享类房源楼盘图
     *
     * @param request
     */
    @RequestMapping("housePic2")
    public void housePic2(HttpServletRequest request, ModelMap modelMap) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "");
        Integer azProjectId = ParamUtils.getInt(request, "azProjectId", 0);
        String buildNum = ParamUtils.getString(request, "buildNum", "");
        String floor = ParamUtils.getString(request, "floor", "");
        Integer minFloor = ParamUtils.getInt(request, "minFloor", 1);

        //通过征收项目、安置项目、楼号得到所分配的houseList
        List<House> houseList = houseService.houseList(zsProjectIdStr, azProjectId, buildNum, floor);
        //得到层号和当前楼层的List<House>对应的map
        Map<String, Map<String, House>> floorAndHouseNumForHouseMap = houseService.getFloorAndHouseNumMap(houseList);
        //获取当前安置项目最高层
        Map<String, Integer> maxFloorMap = houseService.getMaxFloorMap(zsProjectIdStr, azProjectId, buildNum, floor);
        Integer maxFloor = maxFloorMap.get("maxFloor");
        Integer maxHouseNum = maxFloorMap.get("maxHouseNum");
        //房源状态
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("公示颜色");
        //房屋类型
        Map<String, String> houseHoldMap = this.dataDictService.getMapByParentNameForValue_Name("房屋户型");

        modelMap.addAttribute("buildNum", buildNum);
        modelMap.addAttribute("floorAndHouseNumForHouseMap", floorAndHouseNumForHouseMap);
        modelMap.addAttribute("maxFloor", maxFloor);
        modelMap.addAttribute("minFloor", minFloor);
        modelMap.addAttribute("rowNum", Math.round(maxHouseNum / 10) == 0 ? 1 : Math.round(maxHouseNum / 10));
        modelMap.addAttribute("maxHouseNum", maxHouseNum);
        modelMap.addAttribute("colorMap", colorMap);
        modelMap.addAttribute("houseHoldMap", houseHoldMap);
    }

    /**
     * 【凤林二期】选房家庭公示
     *
     * @param request
     * @param modelMap
     */
    @RequestMapping("contractShowForFl")
    public void contractShowForFl(HttpServletRequest request, ModelMap modelMap) {

    }

    /**
     * 选房家庭明细
     *
     * @param request
     * @return
     */
    @RequestMapping("getChooseHouseInfo")
    @ResponseBody
    public Map getChooseHouseInfo(HttpServletRequest request) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "187,188,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207");
        String azProjectIdStr = ParamUtils.getString(request, "azProjectIdStr", "1,5,13");
        Integer pageSize = ParamUtils.getInt(request, "pageSize", 20);
        Integer pageNo = ParamUtils.getInt(request, "pageNo", 1);
        PageBean<Contract> pageBean = new PageBean<Contract>();
        pageBean = this.contractService.getChoosedHouseContractPageBean(zsProjectIdStr, azProjectIdStr, pageSize, pageNo);
        List<Map> dataLists = Lists.newLinkedList();
        Map<Integer, List<House>> houseMap = Maps.newHashMap();
        Map<Integer, List<CarLot>> carLotMap = Maps.newHashMap();
        Map<Integer, List<StorageRoom>> storageRoomMap = Maps.newHashMap();
        if (CollectionUtils.isNotEmpty(pageBean.getDatas())) {
            List<Integer> contractIdList = Lists.newArrayList();
            for (Contract contract : pageBean.getDatas()) {
                contractIdList.add(contract.getId());
            }
            houseMap = this.houseService.getHouseMapByContractIdList(contractIdList);
            carLotMap = this.carLotService.getCarLotMapByContractIdList(contractIdList);
            storageRoomMap = this.storageRoomService.getStorageRoomMapByContractIdList(contractIdList);
        }

        if (CollectionUtils.isNotEmpty(pageBean.getDatas())) {
            Map map = null;
            String strInfo;
            String houseStr;
            String carLotStr;
            String storageRoomStr;
            String syAreaStr;
            for (Contract contract : pageBean.getDatas()) {
                map = null;
                houseStr = "";
                carLotStr = "";
                storageRoomStr = "";
                syAreaStr = "";
                map = Maps.newHashMap();
                map.put("printTableName", StringUtils.getNotNull(contract.getZsProject().getPrintTableName()));
                map.put("name", StringUtils.getNotNull(contract.getName()));
                map.put("chooseHouseNum", StringUtils.getNotNull(contract.getChooseHouseNum()));
                BigDecimal syArea = new BigDecimal("0");
                if (contract.getIsJiSuan() == 2) {
                    syArea = this.contractService.getSyAreaByAzContractId(contract.getId());
                }
                if (CollectionUtils.isNotEmpty(houseMap.get(contract.getId()))) {
                    for (House house : houseMap.get(contract.getId())) {
                        houseStr += house.getAzProject().getMemo() + house.getHouseNumStr() + ",";
                    }
                }
                if (CollectionUtils.isNotEmpty(carLotMap.get(contract.getId()))) {
                    for (CarLot carLot : carLotMap.get(contract.getId())) {
                        carLotStr += carLot.getAzProject().getMemo() + carLot.getHouseNumStr() + ",";
                    }
                }
                if (CollectionUtils.isNotEmpty(storageRoomMap.get(contract.getId()))) {
                    for (StorageRoom storageRoom : storageRoomMap.get(contract.getId())) {
                        storageRoomStr += storageRoom.getAzProject().getMemo() + storageRoom.getHouseNumStr() + ",";
                    }
                }
                map.put("strInfo", houseStr + carLotStr + storageRoomStr);
                map.put("houseStrInfo", houseStr);
                map.put("carLotStrInfo", carLotStr);
                map.put("storageRoomStrInfo", storageRoomStr);
                map.put("chooseHouseDate", DateUtils.dateToStringFormat(contract.getChooseHouseDate(), "yyyy-MM-dd HH:mm"));
                dataLists.add(map);
            }
        }
        Map resultMap = Maps.newHashMap();
        resultMap.put("totalCount", pageBean.getTotalCount());
        resultMap.put("dataLists", dataLists);

        Date nowDate = new Date();
        if (DateUtils.stringToDateTimeCompare(nowDate).equals("上午")) {
            resultMap.put("timeStr", DateUtils.dateToStringDefault(nowDate) + "上午已选房情况");
        } else if (DateUtils.stringToDateTimeCompare(nowDate).equals("下午")) {
            resultMap.put("timeStr", DateUtils.dateToStringDefault(nowDate) + "下午已选房情况");
        }
        return resultMap;
    }

    /**
     * 凤林花苑（二期）
     * 房源表格统计主界面
     */
    @RequestMapping("houseShowForFl")
    public void houseShowForFl(HttpServletRequest request, ModelMap modelMap) {

    }

    /**
     * 凤林花苑（二期）
     * 房源表格统计获取房源数据
     *
     * @param request
     * @return
     */
    @RequestMapping("houseShowHoldForFl")
    public void houseShowHoldForFl(HttpServletRequest request, ModelMap modelMap) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "");
        String azProjectIdStr = ParamUtils.getString(request, "azProjectIdStr", "");
        String houseStyle = ParamUtils.getString(request, "houseStyle", "");
        Map<String, Map<String, Map>> houseHoldDataMap = this.houseService.getHouseHoldForYlMap(zsProjectIdStr, azProjectIdStr,houseStyle);
        Map<String, String> houseHoldMap = this.dataDictService.getMapByParentNameForValue_Name("房屋户型");
        Map<String, AzProject> azProjectMap = this.azProjectService.getAzProjectMap();
        modelMap.addAttribute("houseHoldDataMap", houseHoldDataMap);
        modelMap.addAttribute("houseHoldMap", houseHoldMap);
        modelMap.addAttribute("azProjectMap", azProjectMap);
    }


    /**
     * 楼盘图
     *
     * @param request
     */
    @RequestMapping("housePicAllFor10")
    public void housePicAllFor10(HttpServletRequest request, ModelMap modelMap) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "");
        Integer azProjectId = ParamUtils.getInt(request, "azProjectId", 0);
        String houseStyle = ParamUtils.getString(request, "houseStyle", "");
        String houseHold = ParamUtils.getString(request, "houseHold", "");
        String houseArea = ParamUtils.getString(request, "houseArea", "");
        String buildNumStr = ParamUtils.getString(request, "buildNumStr", "");

        //通过征收项目、安置项目、楼号得到所分配的houseList
        Map<String, List> houseMap = showHjService.houseMapFoJy(zsProjectIdStr, azProjectId, houseHold, houseStyle, null);
        Set set = houseMap.keySet();
        //房源状态
        Map<String, String> colorMap = this.dataDictService.getMapByParentNameForValue_Color("房源状态");
        //房屋类型
        Map<String, String> houseHoldMap = this.dataDictService.getMapByParentNameForValue_Name("房屋户型");
        modelMap.addAttribute("colorMap", colorMap);
        modelMap.addAttribute("houseHoldMap", houseHoldMap);
        List<String> buildNumList = showHjService.buildNumListFoJy(zsProjectIdStr, azProjectId, houseHold, houseStyle, null, buildNumStr);
        modelMap.addAttribute("buildNumList", buildNumList);
        modelMap.addAttribute("houseMap", houseMap);
        modelMap.addAttribute("strUtils", new StringUtils());
    }


    /**
     * 选房家庭公示
     *
     * @param request
     * @param modelMap
     */
    @RequestMapping("contractShowForXy")
    public void contractShowForXy(HttpServletRequest request, ModelMap modelMap) {

    }

    /**
     * 房源饼图、柱状图统计
     */
    @RequestMapping("houseShowPic")
    public void houseShowPic(ModelMap modelMap) {
    }

    /**
     * 饼图数据
     * 相应的征收项目下所分配的房源各楼统计
     *
     * @param request
     * @return
     */
    @RequestMapping("getBuildChooseHouseInfo")
    @ResponseBody
    public Map getBuildChooseHouseInfo(HttpServletRequest request) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "");
        String azProjectIdStr = ParamUtils.getString(request, "azProjectIdStr", "");
        Map<String, Map<String, Map<String, Integer>>> chooseHouseCountMap = this.houseService.getChooseHouseCountMap(zsProjectIdStr, azProjectIdStr);
        Map<String, AzProject> azProjectMap = this.azProjectService.getAzProjectMap();
        StringBuffer build = new StringBuffer("[");//楼号
        StringBuffer chooseCount = new StringBuffer("[");//已选
        StringBuffer noChooseCount = new StringBuffer("[");//未选
        StringBuffer pie = new StringBuffer("[");//饼图已选、未选
        StringBuffer chooseHouseInfo = new StringBuffer("[");//文字显示内容
        BigDecimal qifaArea, syqifangArea;

        if (CollectionUtils.isNotEmpty(chooseHouseCountMap)) {
            Map<String, Map<String, Integer>> itemMap = null;
            Map<String, Integer> itemItemMap = null;
            AzProject azProject = null;
            int houseTotalCount = 0, smallHouseTotalCount = 0, fsHouseTotalCount = 0,
                    normalHouseTotalCount = 0, noSmallHouseTotalCount = 0, noNormalHouseTotalCount = 0,
                    noFsHouseTotalCount = 0, total_choose = 0, total_noChoose = 0, total_chooseCur = 0,
                    bigHouseTotalCount = 0, total_big_choose = 0, total_big_noChoose = 0,
                    noBigHouseTotalCount = 0, total_noBig_choose = 0, total_noBig_noChoose = 0;
            for (String azProjectId : chooseHouseCountMap.keySet()) {
                azProject = null;
                itemMap = null;
                azProject = azProjectMap.get(azProjectId);
                itemMap = chooseHouseCountMap.get(azProjectId);
                if (CollectionUtils.isNotEmpty(itemMap)) {
                    for (String key : itemMap.keySet()) {
                        build.append("'" + key + "幢'").append(",");
                        itemItemMap = null;
                        itemItemMap = itemMap.get(key);

                        //总数量
                        int houseCount = Integer.valueOf(itemItemMap.get("houseCount"));
                        houseTotalCount = IntegerUtils.getSum(houseTotalCount, houseCount);
                        //剩余数量
                        int noChoose = Integer.valueOf(itemItemMap.get("noChooseCount"));
                        total_noChoose = IntegerUtils.getSum(total_noChoose, noChoose);
                        //今日选房数量
                        int choose_cur = Integer.valueOf(itemItemMap.get("chooseCountCur"));
                        total_chooseCur = IntegerUtils.getSum(total_chooseCur, choose_cur);
                        //累计已选数量
                        int choose = Integer.valueOf(itemItemMap.get("chooseCount"));
                        total_choose = IntegerUtils.getSum(total_choose, choose);
                        //小户型数量
                        int smallHouseCount = Integer.valueOf(itemItemMap.get("smallHouseCount"));
                        smallHouseTotalCount = IntegerUtils.getSum(smallHouseTotalCount, smallHouseCount);
                        //小户型剩余数量
                        int noSmallHouseCount = Integer.valueOf(itemItemMap.get("noSmallHouseCount"));
                        noSmallHouseTotalCount = IntegerUtils.getSum(noSmallHouseTotalCount, noSmallHouseCount);
                        //复式数量
                        int fsHouseCount = Integer.valueOf(itemItemMap.get("fsHouseCount"));
                        fsHouseTotalCount = IntegerUtils.getSum(fsHouseTotalCount, fsHouseCount);
                        //复式型剩余数量
                        int noFsHouseCount = Integer.valueOf(itemItemMap.get("noFsHouseCount"));
                        noFsHouseTotalCount = IntegerUtils.getSum(noFsHouseTotalCount, noFsHouseCount);
                        //普通型数量
                        int normalHouseCount = Integer.valueOf(itemItemMap.get("normalHouseCount"));
                        normalHouseTotalCount = IntegerUtils.getSum(normalHouseTotalCount, normalHouseCount);
                        //普通型剩余数量
                        int noNormalHouseCount = Integer.valueOf(itemItemMap.get("noNormalHouseCount"));
                        noNormalHouseTotalCount = IntegerUtils.getSum(noNormalHouseTotalCount, noNormalHouseCount);
                        //大户型总数量（复式、五房）
                        int bigHouseCount = Integer.valueOf(itemItemMap.get("bigHouseCount"));
                        bigHouseTotalCount = IntegerUtils.getSum(bigHouseTotalCount, bigHouseCount);
                        //大户型剩余总数量（复式、五房）
                        int bigHouseNoChooseCount = Integer.valueOf(itemItemMap.get("bigHouseNoChooseCount"));
                        total_big_noChoose = IntegerUtils.getSum(total_big_noChoose, bigHouseNoChooseCount);
                        //非大户型总数量（二房、三房、四房）
                        int noBigHouseCount = Integer.valueOf(itemItemMap.get("noBigHouseCount"));
                        noBigHouseTotalCount = IntegerUtils.getSum(noBigHouseTotalCount, noBigHouseCount);
                        //非大户型剩余数量（二房、三房、四房）
                        int noBigHouseNoChosoeCount = Integer.valueOf(itemItemMap.get("noBigHouseNoChosoeCount"));
                        total_noBig_noChoose = IntegerUtils.getSum(total_noBig_noChoose, noBigHouseNoChosoeCount);

                        chooseCount.append(choose).append(",");//已签约
                        noChooseCount.append(noChoose).append(",");//未签约
                    }
                }
            }
            build.deleteCharAt(build.lastIndexOf(","));
            chooseCount.deleteCharAt(chooseCount.lastIndexOf(","));
            noChooseCount.deleteCharAt(noChooseCount.lastIndexOf(","));
            pie.append(total_choose).append(",").append(total_noChoose);
            chooseHouseInfo.append(houseTotalCount).append(",").append(total_noChoose).append(",");
            chooseHouseInfo.append(total_chooseCur).append(",").append(total_choose).append(",");
            chooseHouseInfo.append(smallHouseTotalCount).append(",").append(noSmallHouseTotalCount).append(",");
            chooseHouseInfo.append(normalHouseTotalCount).append(",").append(noNormalHouseTotalCount).append(",");
            chooseHouseInfo.append(fsHouseTotalCount).append(",").append(noFsHouseTotalCount).append(",");
            chooseHouseInfo.append(bigHouseTotalCount).append(",").append(total_big_noChoose).append(",");
            chooseHouseInfo.append(noBigHouseTotalCount).append(",").append(total_noBig_noChoose);
        }
        build.append("]");
        chooseCount.append("]");
        noChooseCount.append("]");
        pie.append("]");
        chooseHouseInfo.append("]");

        Map map = Maps.newHashMap();
        map.put("build", JSON.parse(build.toString()));
        map.put("chooseCount", JSON.parse(chooseCount.toString()));
        map.put("noChooseCount", JSON.parse(noChooseCount.toString()));
        map.put("pie", JSON.parse(pie.toString()));
        map.put("chooseHouseInfo", JSON.parse(chooseHouseInfo.toString()));
        Date nowDate = new Date();
        if (DateUtils.stringToDateTimeCompare(nowDate).equals("上午")) {
            map.put("timeStr", DateUtils.dateToStringDefault(nowDate) + "上午已选房情况");
        } else if (DateUtils.stringToDateTimeCompare(nowDate).equals("下午")) {
            map.put("timeStr", DateUtils.dateToStringDefault(nowDate) + "下午已选房情况");
        }
        return map;
    }
    /**
     * 相应的征收项目下所分配的房源各楼统计
     *
     * @param request
     * @return
     */
    @RequestMapping("getBuildChooseHouseInfForXy")
    @ResponseBody
    public Map getBuildChooseHouseInfForXy(HttpServletRequest request) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "");
        String azProjectIdStr = ParamUtils.getString(request, "azProjectIdStr", "");
        String houseStyle = ParamUtils.getString(request, "houseStyle", "");
        String memo = ParamUtils.getString(request, "memo", "");
        Map<String, Map<String, Map<String, Integer>>> chooseHouseCountMap = this.houseService.getChooseHouseCountMapForXy(zsProjectIdStr, azProjectIdStr, houseStyle,memo);
        Map<String, AzProject> azProjectMap = this.azProjectService.getAzProjectMap();
        StringBuffer build = new StringBuffer("[");//楼号
        StringBuffer chooseCount = new StringBuffer("[");//已选
        StringBuffer noChooseCount = new StringBuffer("[");//未选
        StringBuffer pie = new StringBuffer("[");//饼图已选、未选
        StringBuffer chooseHouseInfo = new StringBuffer("[");//文字显示内容
        BigDecimal qifaArea, syqifangArea;

        if (CollectionUtils.isNotEmpty(chooseHouseCountMap)) {
            Map<String, Map<String, Integer>> itemMap = null;
            Map<String, Integer> itemItemMap = null;
            AzProject azProject = null;
            int houseTotalCount = 0, smallHouseTotalCount = 0, fsHouseTotalCount = 0,
                    normalHouseTotalCount = 0, noSmallHouseTotalCount = 0, noNormalHouseTotalCount = 0,
                    noFsHouseTotalCount = 0, total_choose = 0, total_noChoose = 0, total_chooseCur = 0,
                    bigHouseTotalCount = 0, total_big_choose = 0, total_big_noChoose = 0,
                    noBigHouseTotalCount = 0, total_noBig_choose = 0, total_noBig_noChoose = 0;
            for (String azProjectId : chooseHouseCountMap.keySet()) {
                azProject = null;
                itemMap = null;
                azProject = azProjectMap.get(azProjectId);
                itemMap = chooseHouseCountMap.get(azProjectId);
                if (CollectionUtils.isNotEmpty(itemMap)) {
                    for (String key : itemMap.keySet()) {
                        build.append("'" + key + "幢'").append(",");
                        itemItemMap = null;
                        itemItemMap = itemMap.get(key);

                        //总数量
                        int houseCount = Integer.valueOf(itemItemMap.get("houseCount"));
                        houseTotalCount = IntegerUtils.getSum(houseTotalCount, houseCount);
                        //剩余数量
                        int noChoose = Integer.valueOf(itemItemMap.get("noChooseCount"));
                        total_noChoose = IntegerUtils.getSum(total_noChoose, noChoose);
                        //今日选房数量
                        int choose_cur = Integer.valueOf(itemItemMap.get("chooseCountCur"));
                        total_chooseCur = IntegerUtils.getSum(total_chooseCur, choose_cur);
                        //累计已选数量
                        int choose = Integer.valueOf(itemItemMap.get("chooseCount"));
                        total_choose = IntegerUtils.getSum(total_choose, choose);
                        //小户型数量
                        int smallHouseCount = Integer.valueOf(itemItemMap.get("smallHouseCount"));
                        smallHouseTotalCount = IntegerUtils.getSum(smallHouseTotalCount, smallHouseCount);
                        //小户型剩余数量
                        int noSmallHouseCount = Integer.valueOf(itemItemMap.get("noSmallHouseCount"));
                        noSmallHouseTotalCount = IntegerUtils.getSum(noSmallHouseTotalCount, noSmallHouseCount);
                        //复式数量
                        int fsHouseCount = Integer.valueOf(itemItemMap.get("fsHouseCount"));
                        fsHouseTotalCount = IntegerUtils.getSum(fsHouseTotalCount, fsHouseCount);
                        //复式型剩余数量
                        int noFsHouseCount = Integer.valueOf(itemItemMap.get("noFsHouseCount"));
                        noFsHouseTotalCount = IntegerUtils.getSum(noFsHouseTotalCount, noFsHouseCount);
                        //普通型数量
                        int normalHouseCount = Integer.valueOf(itemItemMap.get("normalHouseCount"));
                        normalHouseTotalCount = IntegerUtils.getSum(normalHouseTotalCount, normalHouseCount);
                        //普通型剩余数量
                        int noNormalHouseCount = Integer.valueOf(itemItemMap.get("noNormalHouseCount"));
                        noNormalHouseTotalCount = IntegerUtils.getSum(noNormalHouseTotalCount, noNormalHouseCount);
                        //大户型总数量（复式、五房）
                        int bigHouseCount = Integer.valueOf(itemItemMap.get("bigHouseCount"));
                        bigHouseTotalCount = IntegerUtils.getSum(bigHouseTotalCount, bigHouseCount);
                        //大户型剩余总数量（复式、五房）
                        int bigHouseNoChooseCount = Integer.valueOf(itemItemMap.get("bigHouseNoChooseCount"));
                        total_big_noChoose = IntegerUtils.getSum(total_big_noChoose, bigHouseNoChooseCount);
                        //非大户型总数量（二房、三房、四房）
                        int noBigHouseCount = Integer.valueOf(itemItemMap.get("noBigHouseCount"));
                        noBigHouseTotalCount = IntegerUtils.getSum(noBigHouseTotalCount, noBigHouseCount);
                        //非大户型剩余数量（二房、三房、四房）
                        int noBigHouseNoChosoeCount = Integer.valueOf(itemItemMap.get("noBigHouseNoChosoeCount"));
                        total_noBig_noChoose = IntegerUtils.getSum(total_noBig_noChoose, noBigHouseNoChosoeCount);

                        chooseCount.append(choose).append(",");//已签约
                        noChooseCount.append(noChoose).append(",");//未签约
                    }
                }
            }
            build.deleteCharAt(build.lastIndexOf(","));
            chooseCount.deleteCharAt(chooseCount.lastIndexOf(","));
            noChooseCount.deleteCharAt(noChooseCount.lastIndexOf(","));
            pie.append(total_choose).append(",").append(total_noChoose);
            chooseHouseInfo.append(houseTotalCount).append(",").append(total_noChoose).append(",");
            chooseHouseInfo.append(total_chooseCur).append(",").append(total_choose).append(",");
            chooseHouseInfo.append(smallHouseTotalCount).append(",").append(noSmallHouseTotalCount).append(",");
            chooseHouseInfo.append(normalHouseTotalCount).append(",").append(noNormalHouseTotalCount).append(",");
            chooseHouseInfo.append(fsHouseTotalCount).append(",").append(noFsHouseTotalCount).append(",");
            chooseHouseInfo.append(bigHouseTotalCount).append(",").append(total_big_noChoose).append(",");
            chooseHouseInfo.append(noBigHouseTotalCount).append(",").append(total_noBig_noChoose);
        }
        build.append("]");
        chooseCount.append("]");
        noChooseCount.append("]");
        pie.append("]");
        chooseHouseInfo.append("]");

        Map map = Maps.newHashMap();
        map.put("build", JSON.parse(build.toString()));
        map.put("chooseCount", JSON.parse(chooseCount.toString()));
        map.put("noChooseCount", JSON.parse(noChooseCount.toString()));
        map.put("pie", JSON.parse(pie.toString()));
        map.put("chooseHouseInfo", JSON.parse(chooseHouseInfo.toString()));
        Date nowDate = new Date();
        if (DateUtils.stringToDateTimeCompare(nowDate).equals("上午")) {
            map.put("timeStr", DateUtils.dateToStringDefault(nowDate) + "上午已选房情况");
        } else if (DateUtils.stringToDateTimeCompare(nowDate).equals("下午")) {
            map.put("timeStr", DateUtils.dateToStringDefault(nowDate) + "下午已选房情况");
        }
        return map;
    }


    /**
     * 房源表格统计主界面
     */
    @RequestMapping("houseShowForXy")
    public void houseShowForXy(HttpServletRequest request, ModelMap modelMap) {

    }
    /**
     * 房源表格统计获取房源数据
     *
     * @param request
     * @return
     */
    @RequestMapping("houseShowHoldForXy")
    public void houseShowHoldForXy(HttpServletRequest request, ModelMap modelMap) {
        String zsProjectIdStr = ParamUtils.getString(request, "zsProjectIdStr", "");
        String azProjectIdStr = ParamUtils.getString(request, "azProjectIdStr", "");
        String houseStyle = ParamUtils.getString(request, "houseStyle", "");
        String memo = ParamUtils.getString(request, "memo", "");
        Map<String, Map<String, Map>> houseHoldDataMap = this.houseService.getHouseHoldForXyMap(zsProjectIdStr, azProjectIdStr,houseStyle,memo);
        Map<String, String> houseHoldMap = this.dataDictService.getMapByParentNameForValue_Name("房屋户型");
        Map<String, AzProject> azProjectMap = this.azProjectService.getAzProjectMap();
        modelMap.addAttribute("houseHoldDataMap", houseHoldDataMap);
        modelMap.addAttribute("houseHoldMap", houseHoldMap);
        modelMap.addAttribute("azProjectMap", azProjectMap);
    }

    /****************车位预选功能模块***************/
    /**
     * 选择车位列表
     */
    @RequestMapping("carLotList")
    public void carLotList(HttpServletRequest request, ModelMap modelMap) {
        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null && contract.getZsProject() != null, "数据错误！未找到征收项目!");
        modelMap.addAttribute("contract", contract);
    }

    /**
     * 加载车位数据
     *
     * @return
     */
    @RequestMapping("loadCarLotList")
    @ResponseBody
    public Map loadCarLotList(HttpServletRequest request) {
        Integer contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        List<Map> resultData = Lists.newArrayList();
        //得到该征收项目所分配的安置项目所有的车位
        PageBean<CarLot> pageBean = this.carLotService.getCarLotPageByZsProjectId(contract.getZsProject().getId());

        Map<String, DataDict> houseStatusMap = this.dataDictService.getMapByParentNameForValue("房源状态");
        Map<String, DataDict> carLotTypeMap = this.dataDictService.getMapByParentNameForValue("车位类型");
        if (CollectionUtils.isNotEmpty(pageBean.getDatas())) {
            Map<String, Object> mapItem = null;
            Integer houseStatus = null;
            for (CarLot carLot : pageBean.getDatas()) {
                mapItem = null;
                houseStatus = null;
                mapItem = Maps.newHashMap();
                mapItem.put("id", carLot.getId());
                mapItem.put("projectName", carLot.getAzProject().getProjectName());
                mapItem.put("buildNum", carLot.getBuildNum());
                mapItem.put("houseNum", carLot.getHouseNumStr());
                mapItem.put("floor", carLot.getFloor());
                mapItem.put("buildArea", carLot.getBuildArea());
                mapItem.put("carLotTypeStr", StringUtils.dataDictShow(carLotTypeMap.get(carLot.getCarLotType().toString())));
                mapItem.put("houseStatus", carLot.getHouseStatus());
                mapItem.put("price", carLot.getPrice());
                mapItem.put("zhXbPrice", carLot.getZhXbPrice());
                //如果是预留的，则显示为已选状态
                houseStatus = carLot.getHouseStatus().equals(HouseStatus.YULIU.getIndex()) ? HouseStatus.YIXUAN.getIndex() : carLot.getHouseStatus();
                mapItem.put("houseStatusStr", StringUtils.dataDictShow(houseStatusMap.get(houseStatus.toString())));
                resultData.add(mapItem);
            }
        }
        return LayUiUtils.page(pageBean.getTotalCount().intValue(), resultData);
    }


}
